package com.shioirikukuri.service.impl;

import com.shioirikukuri.entity.User;
import com.shioirikukuri.mapper.UserMapper;
import com.shioirikukuri.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;


@Service
public class UserServiceImpl implements IUserService {

	@Autowired
	private UserMapper userMapper;

	/**
	 * 添加消费者用户
	 * @param user 要添加的用户对象
	 * @return
	 */
	@Override
	public User addUser(User user) {
		userMapper.addUser(user);
		return user;
	}

	@Override
	public void deleteUser(Long id) {
		userMapper.deleteUser(id);
	}

	@Override
	public User updateUser(User user) {
		userMapper.updateUser(user);
		return user;
	}

	@Override
	public Optional<User> findUserByPhoneNumber(String phoneNumber) {
		return userMapper.findUserByPhoneNumber(phoneNumber);
	}

	@Override
	public List<User> getAllUsers() {
		return userMapper.getAllUsers();
	}

	@Override
	public Optional<User> getUserById(Long id) {
		return userMapper.getUserById(id);
	}

	@Override
	public void blacklistUser(Long id) {
		userMapper.blacklistUser(id);
	}

	@Override
	public void unblacklistUser(Long id) {
		userMapper.unblacklistUser(id);
	}

	@Override
	public boolean isUserBlacklisted(String phoneNumber) {
		Boolean enabled = userMapper.isUserEnabled(phoneNumber);

		if (enabled == null) {
			// 用户不存在，默认不视为被拉黑
			return false;
		}

		return !enabled;
	}

	@Override
	public List<User> getUsersByRole(String frontDesk) {
		return userMapper.getUsersByRole(frontDesk);
	}

	@Override
	public List<User> getAllConsumers(){
		return userMapper.getAllConsumers();
	}
}